<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

	<script src="jQuery/jquery-3.3.1.min.js"></script>
    <script type="text/javascript">
       //判断是否支持SSE
		if('EventSource' in window){

			//初始化SSE
			var url="http:localhost:8080/sse/push";
			var source=new EventSource(url);
			
			//开启时调用
			source.onopen=(event)=>{
			
				console.log("开启SSE");
			}
		}
		
		//监听message事件
		source.onmessage=(event)=>{
		
			var data=event.data;
		
			$("body").append($("<p>").text(data));
		
		}
		
		//监听like事件
		source.addEventListener('like',function(event){
		
			var data=event.data;
			
			$("body").append($("<p>").text(data));
		},false);
		
		//发生异常时调用
		source.onerror=(event)=>{
		
			console.log(event);
		}
    </script>
</head>
<body>
	<div id="result"></div>
</body>
</html>